/****************************************************
          File Name:36-2.c
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Mon 08 Sep 2014 08:46:23 AM CST
*****************************************************/

#include<stdio.h>
#include<sys/time.h>
#include<sys/resource.h>
#include<sys/wait.h>
#include<stdlib.h>
#include<unistd.h>
#include<errno.h>

void err(char *fun)
{
    perror(fun);
    exit(errno);
}

void show(void)
{
    struct rusage use;
    getrusage(RUSAGE_CHILDREN,&use);
    printf("CPU: %d System: %d\n",use.ru_utime.tv_sec,use.ru_stime.tv_sec);
}

int main(int argc,char *argv[])
{
    if(argc<2)
    {
        printf("%s command arg ...\n",argv[0]);
        exit(1);
    }
    switch(fork())
    {
        case -1:
            err("fork");
        case 0:
            execvp(argv[1],&argv[1]);
            err("execvp");
        default:
            wait(NULL);
            show();
            break;
    }

    exit(0);
}
